exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  /**
     * web端登录
     * @returns {Promise<boolean>}
     */
  loginAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const { username, password } = _this.post('username,password');
      const params = {};
      params.login_ip = _this.ctx.ip;
      params.last_login_time = new Date();

      const loginService = _this.service('sys/LoginService');
      // //验证登录
      const res = yield loginService.checkLogin(username, password, params);
      if (!res.error) {
        const aj = think.ajaxJson();
        aj.result = res.userInfo;
        // aj.attributes.token = res.token;
        aj.msg = '登陆成功';
        aj.attributes.token = res.token;
        // this.ctx.cookie('access_token', res.token, {
        //   domain: 'apigateway-springcloud-test.qingyuanos.com'
        // });
        return _this.json(aj);
      }
      return _this.json(res);
    })();
  }

  /**
     * 注销
     *
     */
  logoutAction() {
    const nameSpace = think.config('nameSpace');
    think.Redis.hdel(nameSpace.LOGIN_USER, this.getUser().userId);
  }

  /**
     *
     */
  cacheRoleAccess() {}
};